<template>
	<view class="qr-code-msg">
		<view class="bg"></view>
		<view class="qr-code-bg">
			<view class="private-school-msg">
				<view class="name">{{schooldName}}</view>
				<view class="msg">扫一扫二维码，加入私塾</view>
				<view class="border"></view>
			</view>
			<view class="qr-code">
				<view class="code">
					<tki-qrcode v-if="val" cid="qrcode1" ref="qrcode" :val="val" :size="464" pdground="#FF9900" :onval="true"
					 :loadMake="true" @result="qrR" />
				</view>
				<view class="msg">
					<button type="primary" @tap="saveQrcode">保存二维码</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
	export default {
		data() {
			return {
				val: '', //要生成的二维码值
				src: '', //二维码生成后的图片地址或base64,
				classroom_id: '',
				schooldName: '私塾名称'
			}
		},
		onLoad(e) {
			this.classroom_id = e.classroom_id
			// 获取二维码
			this.getQrCodeAddress()
			this.getPrivateSchool()
		},
		methods: {
			qrR(res) {
				this.src = res
			},
			saveQrcode() {
				this.$refs.qrcode._saveCode()
			},
			getQrCodeAddress() {
				this.$zapi.apiPost('user/Grade.User/GetClassRoomQR', {
					classroom_id: this.classroom_id
				}).then(res => {
					if (res.data.code == 200 && res.data.data.shareUrl) {
						this.val = res.data.data.shareUrl;
					}
				})
			},
			getPrivateSchool() {
				this.$zapi.apiPost('user/Grade.User/ClassRoomDetail', {
					classroom_id: this.classroom_id
				}).then(res => {
					if (res.data.code == 200) {
						this.schooldName = res.data.data.classroom_name
					}
				})
			}
		}
	}
</script>
<style>
	page {
		height: 100%;
		display: flex;
		align-items: center;
		background: #FF9900;
	}
</style>
<style scoped lang="scss">
	.bg {
		background: #FF9900;
		padding-top: 48upx;
		width: 650upx;
		margin: auto;
		height: 100upx;
		background-image: url(../../../static/image/qRCodebg.png);
		background-size: cover;
	}

	.qr-code-msg {
		width: 650upx;
		margin: 0 auto;
		background: #FFFFFF;

		.qr-code-bg {
			padding: 40upx 0;
			margin: 0 auto;

			.private-school-msg {
				position: relative;
				text-align: center;

				.border {
					padding-top: 58upx;
					width: 590upx;
					margin: auto;
					border-bottom: 1px dashed #707070;
				}

				.name {
					font-size: 36upx;
					font-weight: bold;
					color: #333;
				}

				.msg {
					font-size: 28upx;
					color: #999;
				}
			}

			.private-school-msg::before,
			.private-school-msg::after {
				content: '';
				position: absolute;
				width: 30upx;
				height: 30upx;
				background: #FF9900;
				transform: rotate(45deg);
				bottom: 10upx;
			}

			.private-school-msg::before {
				right: -15upx;
			}

			.private-school-msg::after {
				left: -15upx;
			}

			.qr-code {
				width: 100%;
				padding: 78upx 0 0 0;
				text-align: center;

				.code {
					margin: 0 auto;
					width: 464upx;
					height: 464upx;
				}

				.msg {
					white-space: nowarp;
					overflow: hidden;
					margin: auto;
					width: 260upx;
					padding-top: 60upx;

					button {
						width: 100%;
						background: #FF9900;
						color: #FFFFFF;
						font-size: 36upx;
						font-weight: bold;
						padding: 0;
						margin: 0;
					}
				}
			}
		}

	}
</style>
